using Senparc.Weixin.Entities;
using Senparc.Weixin.QY.AdvancedAPIs.ThirdPartyAuth;
using Senparc.Weixin.QY.CommonAPIs;
using System;
namespace Senparc.Weixin.QY.AdvancedAPIs
{
	public static class ThirdPartyAuthApi
	{
		public static GetSuiteTokenResult GetSuiteToken(string suiteId, string suiteSecret, string suiteTicket, int timeOut = 10000)
		{
			string urlFormat = "https://qyapi.weixin.qq.com/cgi-bin/service/suite_token";
			var data = new
			{
				suite_id = suiteId,
				suite_secret = suiteSecret,
				suite_ticket = suiteTicket
			};
			return CommonJsonSend.Send<GetSuiteTokenResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut);
		}
		public static GetPreAuthCodeResult GetPreAuthCode(string suiteAccessToken, string suiteId, int[] appId, int timeOut = 10000)
		{
			string urlFormat = string.Format("https://qyapi.weixin.qq.com/cgi-bin/service/pre_auth_code?suite_access_token={0}", suiteAccessToken);
			var data = new
			{
				suite_id = suiteId,
				appid = appId
			};
			return CommonJsonSend.Send<GetPreAuthCodeResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut);
		}
		public static GetPermanentCodeResult GetPermanentCode(string suiteAccessToken, string suiteId, string authCode, int timeOut = 10000)
		{
			string urlFormat = string.Format("https://qyapi.weixin.qq.com/cgi-bin/service/permanent_code?suite_access_token={0}", suiteAccessToken);
			var data = new
			{
				suite_id = suiteId,
				auth_code = authCode
			};
			return CommonJsonSend.Send<GetPermanentCodeResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut);
		}
		public static GetAuthInfoResult GetAuthInfo(string suiteAccessToken, string suiteId, string authCorpId, string permanentCode, int timeOut = 10000)
		{
			string urlFormat = string.Format("https://qyapi.weixin.qq.com/cgi-bin/service/auth_info?suite_access_token={0}", suiteAccessToken);
			var data = new
			{
				suite_id = suiteId,
				auth_corpid = authCorpId,
				permanent_code = permanentCode
			};
			return CommonJsonSend.Send<GetAuthInfoResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut);
		}
		public static GetAgentResult GetAgent(string suiteAccessToken, string suiteId, string authCorpId, string permanentCode, string agentId, int timeOut = 10000)
		{
			string urlFormat = string.Format("https://qyapi.weixin.qq.com/cgi-bin/service/agent?suite_access_token={0}", suiteAccessToken);
			var data = new
			{
				suite_id = suiteId,
				auth_corpid = authCorpId,
				permanent_code = permanentCode,
				agentid = agentId
			};
			return CommonJsonSend.Send<GetAgentResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut);
		}
		public static QyJsonResult SetAgent(string suiteAccessToken, string suiteId, string authCorpId, string permanentCode, ThirdParty_AgentData agent, int timeOut = 10000)
		{
			string urlFormat = string.Format("https://qyapi.weixin.qq.com/cgi-bin/service/agent?suite_access_token={0}", suiteAccessToken);
			var data = new
			{
				suite_id = suiteId,
				auth_corpid = authCorpId,
				permanent_code = permanentCode,
				agent = agent
			};
			return CommonJsonSend.Send<QyJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut);
		}
		public static GetCorpTokenResult GetCorpToken(string suiteAccessToken, string suiteId, string authCorpId, string permanentCode, int timeOut = 10000)
		{
			string urlFormat = string.Format("https://qyapi.weixin.qq.com/cgi-bin/service/corp_token?suite_access_token={0}", suiteAccessToken);
			var data = new
			{
				suite_id = suiteId,
				auth_corpid = authCorpId,
				permanent_code = permanentCode
			};
			return CommonJsonSend.Send<GetCorpTokenResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut);
		}
	}
}
